﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UserDefinedForms.Entities;
using UserDefinedForms.Business;

namespace UDFDesign.GUIComponent.CustomControl
{

    public class ControlFactory
    {
        private static int indentity = 0;
        private static ControlListItemService listItemService = new ControlListItemService();
        public void resetIndentity()
        {
            indentity = 0;
        }

        public static DesignableControl createControl(DrawingBoard board, FormControl entity)
        {

            ControlTypes type = (ControlTypes)Enum.ToObject(typeof(ControlTypes), entity.ControlTypeId);
            switch (type)
            {
                case ControlTypes.TextBox:
                    {
                        DesignableTextBox txtBox = new DesignableTextBox(entity);
                        txtBox.DrawingBoard = board;
                        return txtBox;
                    }
                case ControlTypes.RadioButton:
                    {
                        DesignableRadioButton rdBtn = new DesignableRadioButton(entity);
                        rdBtn.DrawingBoard = board;
                        return rdBtn;
                    }
                case ControlTypes.NumberTextBox:
                    {
                        DesignableNumberTextBox nbTxt = new DesignableNumberTextBox(entity);
                        nbTxt.DrawingBoard = board;
                        return nbTxt;
                    }
                case ControlTypes.DateTimePicker:
                    {
                        DesignableDateTimePicker dtPicker = new DesignableDateTimePicker(entity);
                        dtPicker.DrawingBoard = board;
                        return dtPicker;
                    }
                case ControlTypes.CheckBox:
                    {
                        DesignableCheckBox ckBox = new DesignableCheckBox(entity);
                        ckBox.DrawingBoard = board;
                        return ckBox;
                    }
                case ControlTypes.AutoCalculate:
                    {
                        DesignableAutoCalculate autoCal = new DesignableAutoCalculate(entity);
                        autoCal.DrawingBoard = board;
                        return autoCal;
                    }
                case ControlTypes.ComboBox:
                    {
                        DesignableComboBox cmbBox = new DesignableComboBox(entity);
                        cmbBox.DrawingBoard = board;
                        return cmbBox;
                    }
            }

            return null;

        }

        public static DesignableControl createControl(DrawingBoard board, ControlTypes type)
        {
            String name = "Control" + indentity;
            indentity++;
            switch (type)
            {
                case ControlTypes.TextBox:
                    {
                        DesignableTextBox txtBox = new DesignableTextBox();
                        txtBox.DrawingBoard = board;
                        txtBox.ControlORM.Name = name;
                        return txtBox;
                    }
                case ControlTypes.RadioButton:
                    {
                        DesignableRadioButton rdBtn = new DesignableRadioButton();
                        rdBtn.DrawingBoard = board;
                        rdBtn.ControlORM.Name = name;
                        return rdBtn;
                    }
                case ControlTypes.NumberTextBox:
                    {
                        DesignableNumberTextBox nbTxt = new DesignableNumberTextBox();
                        nbTxt.DrawingBoard = board;
                        nbTxt.ControlORM.Name = name;
                        return nbTxt;
                    }
                case ControlTypes.DateTimePicker:
                    {
                        DesignableDateTimePicker dtPicker = new DesignableDateTimePicker();
                        dtPicker.DrawingBoard = board;
                        dtPicker.ControlORM.Name = name;
                        return dtPicker;
                    }
                case ControlTypes.CheckBox:
                    {
                        DesignableCheckBox ckBox = new DesignableCheckBox();
                        ckBox.DrawingBoard = board;
                        ckBox.ControlORM.Name = name;
                        return ckBox;
                    }
                case ControlTypes.AutoCalculate:
                    {
                        DesignableAutoCalculate autoCal = new DesignableAutoCalculate();
                        autoCal.DrawingBoard = board;
                        autoCal.ControlORM.Name = name;
                        return autoCal;
                    }
                case ControlTypes.ComboBox:
                    {
                        DesignableComboBox cmbBox = new DesignableComboBox();
                        cmbBox.DrawingBoard = board;
                        cmbBox.ControlORM.Name = name;
                        return cmbBox;
                    }
            }

            return null;
        }
    }
}
